<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changMonth:true});
	$(".view").toggle(function(){
		$(this).parent().parent().next().show();
	},function(){
		$(this).parent().parent().next().hide();
	});
});
</script>
<fieldset>
	<legend>查询条件</legend>
	<form method="get">
	<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
		<table class="form_table">
		<tr>
			<th>订单编号</th>
			<td><input type="text" name="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
		</tr>
		<tr>
			<th>产品编号</th>
			<td><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>" /></td>
		</tr>
		<tr>
			<th>追踪号</th>
			<td><input type="text" name="tracking_number" value="<?=isset($_GET['tracking_number']) ? $_GET['tracking_number'] : ''?>" /></td>
		</tr>
		<tr>
			<th>发货时间</th>
			<td>
				<input type="text" class="datepicker" name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : ''?>" /> to
				<input type="text" class="datepicker" name="end_shipped_time" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : ''?>" />
			</td>
		</tr>
		<tr>
			<th width="60">邮寄方式</th>
			<td>
				<?php foreach($shipping_method as $sm):?>
				<label><input type='checkbox' name="shipping_method[<?=$sm['id']?>]" value="<?=$sm['id']?>" <?if (isset($_GET['shipping_method']) && array_key_exists($sm['id'], $_GET['shipping_method'])) echo "checked='checked'";?>/><?=$sm['name'];?></label>
				<?php endforeach;?>
			</td>
		</tr>
		<tr>
			<th></th>
			<td><input type="submit" name="submit" class="button" value="查询" /></td>
		</tr>
		</table>
	</form>
</fieldset>
<table class="list_table" width="100%">
<tr>
	<th width="30"></th>
	<th width="100">本地单号</th>
	<th>网站</th>
	<th>网站单号</th>
	<th>买家ID</th>
	<th width="130">发货时间</th>
	<th>邮寄方式</th>
	<th>重量</th>
	<th width="120">状态</th>
	<th width="100">操作</th>
</tr>
<? foreach($sales_order as $so): ?>
<tr>
	<td><input type='checkbox' value='<?=$so['id']?>'/></td>
	<td><?=$so['number']?></td>
	<td><?=$so['shop_name']?></td>
	<td><?=$so['shop_order_number']?></td>
	<td><?=$so['shop_buyer_id']?></td>
	<td><?=$so['shipped_time']?></td>
	<td><?=$so['shipping_method_name']?></td>
	<td><?=sprintf('%.2f',$so['weight'])?>g</td>
	<td>
		<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $so['handle_status'], 'name')?>
		<span class="<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $so['handle_status'], 'icon_class')?>"></span>
		<?if ($so['has_sales_notes']):?><span class="sales_notes_icon"></span><?endif;?>
		<?if ($so['has_warehouse_notes']):?><span class="warehouse_notes_icon"></span><?endif;?>
		<?foreach (Q::ini('custom_flag/sales_order_synchronous_flag') as $sf):?>
		<?if($so['synchronous_flag'] == $sf['value']):?><div><font color="green"><?=$sf['name']?></font><span class="express_icon"></span></div><?endif;?>
		<?endforeach;?>
	</td>
	<td>
		<a class="view" href="javascript:void(0);">查看</a>
		<input type="hidden" value="<?=$so['id']?>" />
	</td>
</tr>
<tr class="detail" style="display:none">
	<td colspan="25">
		<table width="100%" class="list_table">
			<tr>
				<th width="15%">仓库</th>
				<td width="35%"><?=$so['warehouse_name']?></td>
				<th width="15%">制单人</th>
				<td width="35%"><?=$so['make_user_name']?></td>
			</tr>
			<tr>
				<th>发货类型</th>
				<td><?=Helper_BSS_Normal::getIniOne('sales_order_send_method', 'value', $so['send_method'], 'name')?></td>
				<th>支付方式</th>
				<td><?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $so['payment_method'], 'name')?></td>
			</tr>
			<tr>
				<th>邮寄方式</th>
				<td><?=$so['shipping_method_name']?></td>
				<th>交易号</th>
				<td><?=$so['transaction_id']?></td>
			</tr>
			<tr>
				<th>买家姓名</th>
				<td><?=$so['fullname']?></td>
				<th>买家Email</th>
				<td><?=$so['email']?></td>
			</tr>
			<tr>
				<th>买家电话</th>
				<td><?=$so['phone']?></td>
				<th>收货地址1</th>
				<td><?=$so['street1']?></td>
			</tr>
			<tr>
				<th>收货地址2</th>
				<td><?=$so['street2']?></td>
				<th>城市</th>
				<td><?=$so['city']?></td>
			</tr>
			<tr>
				<th>州/省</th>
				<td><?=$so['state']?></td>
				<th>邮政编码</th>
				<td><?=$so['zip']?></td>
			</tr>
			<tr>
				<th>国家</th>
				<td><?=$so['country']?></td>
				<th>国家(中文)</th>
				<td><?=$so['country_cn']?></td>
			</tr>
			<tr>
				<th>运费</th>
				<td><?=$so['currency_symbol']?><?=sprintf('%.2f',$so['shipping_fee'])?></td>
				<th>折扣</th>
				<td><?=$so['currency_symbol']?><?=sprintf('%.2f',$so['discount'])?></td>
			</tr>
			<?if ($so['address_notes']):?>
			<tr>
				<th>地址备注</th>
				<td align="left" colspan="3"><?=$so['address_notes']?></td>
			</tr>
			<?endif;?>
			<?if ($so['sales_notes']):?>
			<tr>
				<th>销售备注</th>
				<td align="left" colspan="3">
				<?foreach ($so['sales_notes'] as $ssn):?>
				<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
			<?if ($so['warehouse_notes']):?>
			<tr>
				<th>仓库备注</th>
				<td align="left" colspan="3">
				<?foreach ($so['warehouse_notes'] as $ssn):?>
				<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
			<?if ($so['customer_notes']):?>
			<tr>
				<th>客人备注</th>
				<td align="left" colspan="3">
				<?foreach($so['customer_notes'] as $scn):?>
				<p><?=$scn['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
		</table>
		<div align="left"><strong>销售订单产品信息</strong></div>
		<table width="100%" class="list_table">
			<tr>
				<th>产品编号</th>
				<th>数量</th>
				<th>可用库存</th>
				<th>ShopItemId</th>
				<th>ShopTransactionId</th>
			</tr>
			<?$total_quantity = 0;?>
			<?foreach ($so['item'] as $so_item):?>
			<?$total_quantity += $so_item['quantity'];?>
			<tr>
				<td>
					<?=$so_item['number']?>
					<?if ($so_item['pic_url']):?>
						<?$pretty_photo_number = 0;?>
						<?foreach ($so_item['pic_url'] as $so_item_photo):?>
							<a rel="pretty_photo[<?=$so_item['id']?>]" href="<?= $so_item_photo?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
							<?$pretty_photo_number = 1;?>
						<?endforeach;?>
					<?endif;?>
				</td>
				<td><?=$so_item['quantity']?></td>
				<td><?=($so_item['available_quantity'] < $so_item['quantity']) ? "<span class='red'>{$so_item['available_quantity']}</span>" : $so_item['available_quantity'] ;?></td>
				<td><?=$so_item['shop_item_id']?></td>
				<td><?=$so_item['shop_transaction_id']?></td>
			</tr>
			<?endforeach?>
			<tr>
				<td colspan="1">小计</td>
				<td><?=$total_quantity?></td>
				<td colspan="4"></td>
			</tr>
		</table>
	</td>
</tr>
<? endforeach; ?>
</table>
<?=$page?>
<?php $this->_endblock(); ?>